#ifndef GROUPCHAT_H
#define GROUPCHAT_H

#include <QWidget>

// 群聊
#include <QTcpSocket>
#include <QTcpSocket>
#include <QListWidget>
#include <QTextEdit>
#include <QLineEdit>
#include <QPushButton>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QTimer>
#include "client_connet.h"

namespace Ui {
class GroupChat;
}

class GroupChat : public QWidget
{
    Q_OBJECT

public:
    explicit GroupChat(QWidget *parent = nullptr);

    //设置界面内嵌属性（并重载）
    void setMfrend(QString IDE,QString name1,int fid)
    {
        frend.friendloginid = IDE;
        frend.name = name1;
        frend.FriendGroups = fid;
    }
    void setMfrend(frientds f)
    {
        frend = f;
    }

    void setUser(frientds fe)
    {
        frend = fe;
    }

    void recvMessage(QString);

private slots:
    void on_SendBtn_clicked();
    void appendMessage(const QString &sender, const QString &message, Qt::Alignment alignment, const QColor &textColor);
    void updateUserList(const QString &message);
private:
    Ui::GroupChat *ui;
    QTimer reconnectTimer; // 用于重连的定时器
    int currentReconnectAttempt = 0; // 当前重连尝试次数
    const int maxReconnectAttempts = 5;// 最多重连尝试次数
    frientds frend;
};

#endif // GROUPCHAT_H
